Completed
Push — master ( cd2326...65f97e )
by Maxence
03:06
created

resultCircles.leaveCircleResult   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 3
nc 3
nop 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 3 1
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: actions */
31
/** global: nav */
32
/** global: elements */
33
/** global: curr */
34
/** global: api */
35
36
37
var resultCircles = {
38
39
40
	joinCircleResult: function (result) {
41
		if (result.status === 0) {
42
			OCA.notification.onFail(
43
				t('circles', "Cannot join this circle") + ': ' +
44
				((result.error) ? result.error : t('circles', 'no error message')));
45
			return;
46
		}
47
48
		elements.removeMemberslistEntry(result.member.user_id);
49
		if (result.member.level === define.levelMember) {
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
50
			OCA.notification.onSuccess(
51
				t('circles', "You have successfully joined this circle"));
52
		} else {
53
			OCA.notification.onSuccess(
54
				t('circles', "You have requested to join this circle"));
55
		}
56
		actions.selectCircle(result.circle_id);
57
	},
58
59
60
	leaveCircleResult: function (result) {
61
		if (result.status === 1) {
62
63
			elements.mainUIMembersTable.children("[member-id='" + result.name + "']").each(
64
				function () {
65
					$(this).hide(300);
66
				});
67
68
			actions.selectCircle(result.circle_id);
69
			OCA.notification.onSuccess(
70
				t('circles', "You have successfully left this circle"));
71
			return;
72
		}
73
74
		OCA.notification.onFail(
75
			t('circles', "Cannot leave this circle") + ': ' +
76
			((result.error) ? result.error : t('circles', 'no error message')));
77
	},
78
79
80
	destroyCircleResult: function (result) {
81
		if (result.status === 1) {
82
83
			actions.unselectCircle(result.circle_id);
84
			OCA.notification.onSuccess(
85
				t('circles', "You have successfully deleted this circle"));
86
			return;
87
		}
88
89
		OCA.notification.onFail(
90
			t('circles', "Cannot delete this circle") + ': ' +
91
			((result.error) ? result.error : t('circles', 'no error message')));
92
	},
93
94
	// settingsCircleResult: function (result) {
95
	// 	console.log(result);
96
	// },
97
98
	createCircleResult: function (result) {
99
		var type = actions.getStringTypeFromType(result.type);
100
101
		if (result.status === 1) {
102
			OCA.notification.onSuccess(t('circles', " {type} '{name}' created", {
103
				type: type,
104
				name: result.name
105
			}));
106
			elements.emptyCircleCreation();
107
			nav.displayCirclesList(result.circle.type);
108
			actions.selectCircle(result.circle.id);
109
			return;
110
		}
111
112
		OCA.notification.onFail(
113
			t('circles', " {type} '{name}' could not be created", {
114
				type: type,
115
				name: result.name
116
			}) + ': ' +
117
			((result.error) ? result.error : t('circles', 'no error message')));
118
	},
119
120
121
	selectCircleResult: function (result) {
122
123
		elements.mainUIMembersTable.emptyTable();
124
		if (result.status < 1) {
125
			OCA.notification.onFail(
126
				t('circles', 'Issue while retrieving the details of this circle') + '" ' +
127
				((result.error) ? result.error : t('circles', 'no error message')));
128
			return;
129
		}
130
131
		elements.navigation.children('.circle').removeClass('selected');
132
		elements.navigation.children(".circle[circle-id='" + result.circle_id + "']").each(
133
			function () {
134
				$(this).addClass('selected');
135
			});
136
137
		elements.emptyContent.hide(800);
138
		elements.mainUI.fadeIn(800);
139
		curr.circle = result.circle_id;
140
		curr.circleLevel = result.details.user.level;
141
		curr.circleStatus = result.details.user.status;
142
143
		nav.displayCircleDetails(result.details);
144
		nav.displayMembersInteraction(result.details);
145
		nav.displayMembers(result.details.members);
146
	},
147
148
149
	listCirclesResult: function (result) {
150
151
		if (result.status < 1) {
152
			OCA.notification.onFail(
153
				t('circles', 'Issue while retrieving the list of circles') + '; ' +
154
				((result.error) ? result.error : t('circles', 'no error message')));
155
			return;
156
		}
157
158
		elements.resetCirclesList();
159
160
		var data = result.data;
161
		for (var i = 0; i < data.length; i++) {
162
			var tmpl = elements.generateTmplCircle(data[i]);
163
			elements.navigation.append(
164
				'<div class="circle" circle-id="' + data[i].id + '">' + tmpl + '</div>');
165
		}
166
167
		elements.navigation.children('.circle').on('click', function () {
168
			actions.selectCircle($(this).attr('circle-id'));
169
		});
170
	}
171
172
173
};
174